package com.martin.dms.web.beans;

import java.io.Serializable;
import java.util.List;

import org.springframework.binding.message.MessageBuilder;
import org.springframework.binding.message.MessageContext;
import org.springframework.binding.validation.ValidationContext;

public class SupplierManagementBean implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 9001782624123625236L;

    private String supplierNameFilter = "*";
    private String supplierEmailFilter = "*";
    private String suppliedItemNameFilter = "*";

    private List<Long> supplierIds;

    /**
     * @param supplierNameFilter the supplierNameFilter to set
     */
    public void setSupplierNameFilter(String supplierNameFilter) {
        this.supplierNameFilter = supplierNameFilter;
    }

    /**
     * @return the supplierNameFilter
     */
    public String getSupplierNameFilter() {
        return supplierNameFilter;
    }

    /**
     * @param supplierEmailFilter the supplierEmailFilter to set
     */
    public void setSupplierEmailFilter(String supplierEmailFilter) {
        this.supplierEmailFilter = supplierEmailFilter;
    }

    /**
     * @return the supplierEmailFilter
     */
    public String getSupplierEmailFilter() {
        return supplierEmailFilter;
    }

    /**
     * @param suppliedItemNameFilter the suppliedItemNameFilter to set
     */
    public void setSuppliedItemNameFilter(String suppliedItemNameFilter) {
        this.suppliedItemNameFilter = suppliedItemNameFilter;
    }

    /**
     * @return the suppliedItemNameFilter
     */
    public String getSuppliedItemNameFilter() {
        return suppliedItemNameFilter;
    }

    /**
     * @param supplierIds the supplierIds to set
     */
    public void setSupplierIds(List<Long> supplierIds) {
        this.supplierIds = supplierIds;
    }

    /**
     * @return the supplierIds
     */
    public List<Long> getSupplierIds() {
        return supplierIds;
    }

    public void validateSuppliersManagement(ValidationContext validationContext) {
        MessageContext messageContext = validationContext.getMessageContext();
        String userEvent = validationContext.getUserEvent();
        if (userEvent.equals("delete") || userEvent.equals("edit") || userEvent.equals("viewDetails")) {
            if (supplierIds == null || supplierIds.size() != 1) {
                messageContext.addMessage(new MessageBuilder().error().code("error.selectOneSupplier").build());
            }
        }
    }
}
